package com.hmkj.core.service.amount.impl;

import com.hmkj.common.utils.StringUtils;
import com.hmkj.core.mapper.amount.AccountLogMapper;
import com.hmkj.common.baseMapper.GenericMapper;
import com.hmkj.core.po.amount.AccountLog;
import com.hmkj.core.service.amount.AccountLogService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 资金记录业务相关Service接口实现<br>
 *
 * @author donfy
 * @ClassName: AccountLogServiceImpl
 * @date 2017-08-15 03:10:41
 */
@Service
@Scope("prototype")
@Transactional(rollbackFor = Exception.class)
public class AccountLogServiceImpl implements AccountLogService {

    @Resource
    private AccountLogMapper accountLogMapper;

    @Override
    public GenericMapper<AccountLog,Integer> _getMapper() {
        return accountLogMapper;
    }

    @Override
    public BigDecimal selectSumByType(AccountLog.TYPE t, AccountLog.TYPE t1,Integer userId) {
        Map<String,Object> param  = new HashMap<>();
        param.put("whereSql","("+t.code+","+t1.code+") and user_id = "+userId);
        return accountLogMapper.selectSumByType(param);
    }

    @Override
    public BigDecimal selectSumByAirectionType(AccountLog.DIRECTION direction, AccountLog.TYPE type, Integer userId) {
        return accountLogMapper.selectSumByAirectionType(direction.code,type.code,userId);
    }

    @Override
    public BigDecimal selectSumAmountByType(AccountLog.TYPE type,String startTime,String endTime,Integer agentId) {
        Map<String,Object> param  = new HashMap<>();
        param.put("type",type.code);
        param.put("startTime",startTime);
        param.put("endTime",endTime);
        param.put("agentId",agentId);
        return accountLogMapper.selectSumAmountByType(param);
    }
}
